package com.apps.ftapp.ui;


import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.TextView;

import com.apps.ftapp.R;


public class MyProgressDialog extends Dialog {

    public MyProgressDialog(Context context, int theme) {
        super(context, theme);
    }

    public static MyProgressDialog createDialog(Context context) {
        MyProgressDialog dialog = new MyProgressDialog(context, R.style.dialog);
        dialog.setContentView(R.layout.myprogressdialog);
        dialog.getWindow().getAttributes().gravity = Gravity.CENTER;
        return dialog;
    }

    public MyProgressDialog setMsg(String msg) {
        TextView textView = findViewById(R.id.loading_msg);
        if (textView != null) {
            textView.setText(msg);
        }
        return this;
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        ImageView imageView = findViewById(R.id.loadingImg);
        AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
        if (hasFocus) {
            if (animationDrawable != null) {
                animationDrawable.start();
            }
        } else {
            if (animationDrawable != null) {
                animationDrawable.stop();
            }
        }
    }

}
